package com.zh.web.openApi;

import com.zh.common.exception.BusinessException;
import com.zh.web.base.ApiResult;
import com.zh.web.config.DefaultFeignConfig;
import com.zh.web.domain.system.dto.DeleteFileDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@FeignClient(name = "ls-service-system", path = "/file", configuration = {DefaultFeignConfig.class}, contextId = "fileClient", fallback = FileClientFallback.class)

public interface FileClient {

    @PostMapping(value = "/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ApiResult<String> uploadFile(@RequestParam("fileName") String fileName,
                                 @RequestPart("file") MultipartFile file);

    @DeleteMapping
    ApiResult<String> deleteFileByUrl(@RequestBody DeleteFileDto deleteFileDto);
}

class FileClientFallback implements FileClient {

    @Override
    public ApiResult<String> uploadFile(String fileName, MultipartFile file) {
        throw new BusinessException("系统繁忙");
    }

    @Override
    public ApiResult<String> deleteFileByUrl(DeleteFileDto deleteFileDto) {
        throw new BusinessException("系统繁忙");
    }
}